I want to compare 2 strings. One is from user and one will be from a file.
My file contains this.
Philippines
Olives
Polymerization
Coconut
I dont get my expected output. Here's my code. Pls help
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<iostream>
int main()
{
char answer[512];
char str[512];
printf("INPUT STRING: ");
scanf("%s", &str);
FILE *fp;
fp=fopen("JL-answers[easy].txt", "r");
if (fp==NULL)
{
printf("ERROR OPENING FILE");
}
fscanf(fp,"%s", answer);
if(strcmp(str, answer)==0)
printf("STRING FOUND.\n");
else
printf("STRING NOT FOUND.\n");
fclose(fp);
return 0;
}